// myself/daily/HealthDaily.js
import api from "../../utils/api.js";
import network from "../../utils/network.js";
import notification from '../../utils/notification_center.js';
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    finish: true,
    items: [{
        name: 'no',
        value: '无',
        checked: true
      },
      {
        name: 'yes',
        value: '有',
        checked: false
      },
    ],
    value: 'no',
    history: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let history = wx.getStorageSync('history')
    if (history) {
      this.setData({
        history: history
      })
    }

    this.toast = this.selectComponent("#toast");
  },

  radioChange: function(e) {
    this.setData({
      value: e.detail.value
    })
  },

  formSubmit: function(e) {
    let formValue = e.detail.value;
    if (formValue.fangang == '') {
      this.toast.showToast('请输入新增入返岗人数');
      return;
    } else if (formValue.zaigang == '') {
      this.toast.showToast('请输入当日在岗人数');
      return;
    } else if (formValue.old_count == '') {
      this.toast.showToast('请输入2019年年底员工人数');
      return;
    } else if (formValue.channeng == '') {
      this.toast.showToast('请输入产能利用率');
      return;
    } else if (formValue.isHas == 'yes') {
      if (formValue.you == '') {
        this.toast.showToast('请输入发热、乏力、干咳人数');
        return;
      }
    }
    let history = {
      fangang: formValue.fangang,
      zaigang: formValue.zaigang,
      old_count: formValue.old_count,
      channeng: formValue.channeng
    }
    wx.setStorageSync('history', history);

    network.postJson(this, api.fangang, {
      adminid: app.globalData.userInfo.uid,
      token: app.globalData.userInfo.token,
      newlyadded: formValue.fangang,
      onduty: formValue.zaigang,
      oldnum: formValue.old_count,
      capacity: formValue.channeng,
      issymptom: formValue.isHas == 'yes' ? 1 : 0,
      issymptomnum: formValue.you ? formValue.you : 0
    }).then(res => {
      notification.postNotificationName('HealthRecord');
      this.toast.showToast('提交成功');
    });
  }
})